//
//  NNDefenderController.m
//  CommonTool
//
//  Created by Name i on 2022/4/13.
//

#import "NNDefenderController.h"
#import "NNTimerProxy.h"
#import "NSTimer+TimerSafe.h"
#import <KVOController/KVOController.h>



@interface TTTPerson: NSObject

@property (nonatomic, copy) NSString *name;

@end

@implementation TTTPerson

@end


@interface NNDefenderController ()

@property (nonatomic, strong) TTTPerson *person;

@property (nonatomic, strong) FBKVOController *kvoController;

@end

@implementation NNDefenderController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithTitle:@"add"
                                                            style:UIBarButtonItemStyleDone
                                                           target:self
                                                           action:@selector(testAddObserver)];
    
    UIBarButtonItem *remove = [[UIBarButtonItem alloc] initWithTitle:@"remove"
                                                            style:UIBarButtonItemStyleDone
                                                           target:self
                                                           action:@selector(testRemoveObserver)];

    self.navigationItem.rightBarButtonItems = @[add, remove];
    
    self.person = [[TTTPerson alloc] init];
    self.kvoController = [[FBKVOController alloc] initWithObserver:self];
    [self.kvoController observe:self.person
                        keyPath:@"name"
                        options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
                          block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
        NSLog(@"change = %@", change);
    }];
}

- (void)testAddObserver {
    
    
    
        NSString *str = [NSString stringWithFormat:@"12"];
        NSString *str1 = [NSString stringWithFormat:@"aefasfasdfasfdasf"];
        NSLog(@"%@  %@",[str class],[str1 class]);


//    self.person.name = @"123";
//    self.person.name = @"234234";
}

- (void)testRemoveObserver {
    [self testAddObserver];
//    [self.kvoController unobserve:self.person];
}

- (void)dealloc {
    [self.kvoController unobserve:self.person];

}

@end
